package com.beiing.tianshuai.tianshuai.mine.ui;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class IdentificationStatusActivity extends BaseActivity {

    @BindView(R.id.toolbar_iv_back)
    ImageView mToolbarIvBack;
    @BindView(R.id.toolbar_tv_title)
    TextView mToolbarTvTitle;
    @BindView(R.id.iv_identification_icon)
    ImageView mIvIdentificationIcon;
    @BindView(R.id.tv_identification_status)
    TextView mTvIdentificationStatus;
    @BindView(R.id.tv_reidentification)
    TextView mTvReidentification;
    @BindView(R.id.tv_identification_message)
    TextView mTvIdentificationMessage;

    private Unbinder            mUnbinder;
    private Context             mContext;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_identification_status;
    }

    @Override
    protected void init() {
        mUnbinder = ButterKnife.bind(this);
        mContext = this;
        Intent intent = getIntent();
        String status = intent.getStringExtra("status");
        initToolbar();
        changeActivity(status); // 根据用户当前的认证审核状态跳转到新的页面
        initListener();
    }

    private void initToolbar() {
        mToolbarTvTitle.setText("认证");
        mToolbarIvBack.setVisibility(View.VISIBLE);
        mToolbarIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void changeActivity(String status) {
        /*
         * 认证等级
         * 0 - 未认证
         * 1 - 审核中
         * 2 - 个人
         * 3 - 组织
         * 4 - 企业
         * 5 - 审核失败
         */
        switch (status) {
            case "0":
                Intent toIdentify = new Intent(mContext, IdentificationActivity.class);
                startActivity(toIdentify);
                finish();
                break;
            case "1":
                mIvIdentificationIcon.setImageResource(R.mipmap.under_review);
                mTvIdentificationStatus.setText("您的认证已经提交");
                mTvIdentificationMessage.setText("我们将在3-5个工作日内完成审核，请耐心等待");
                break;
            case "2":
            case "3":
            case "4":
                mIvIdentificationIcon.setImageResource(R.mipmap.under_review);
                mTvIdentificationStatus.setText("您的认证已经通过");
                mTvIdentificationMessage.setText("我们将在3-5个工作日内完成审核，请耐心等待");
                Intent identificationInfoIntent = new Intent(mContext, IdentificationInfoActivity.class);
                identificationInfoIntent.putExtra("type", status);
                startActivity(identificationInfoIntent);
                finish();
                break;
            case "5":
                mTvReidentification.setVisibility(View.VISIBLE);
                mTvReidentification.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); // 下划线
                mTvReidentification.getPaint().setAntiAlias(true);                  // 抗锯齿
                mIvIdentificationIcon.setImageResource(R.mipmap.review_failed);
                mTvIdentificationStatus.setText("您的认证信息未通过");
                mTvIdentificationMessage.setText("您上传的资质照片不符合要求，请重新上传");
                break;
        }
    }

    private void initListener() {
        mTvReidentification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, IdentificationActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mUnbinder != null) {
            mUnbinder.unbind();
        }
    }
}
